/********************************************************************************
*
* Analysis Main paper
*
********************************************************************************/

set more off
clear 

* set local path to the replication package here:
global path_package "../_replication_package/"
cd "$path_package"

/************************************************************************
*
* Results
*
************************************************************************/


/***************************
*
* Section 4 (Swiss labor market data)
*
*****************************/

*** Figure 1

insheet using "$path_package/Other data/SLFS/wagedata_aggregate.csv"

tempfile temp
save `temp', replace

forvalues i=1(1)3 {

insheet using "$path_package/Other data/Perception_data/Sample`i'/I_j.csv", clear
merge 1:m noga20084 using `temp', gen(merge`i')
save `temp', replace

}

* Panel (a)
preserve
keep if i_j_s1!=.
label define nogaGraph 1200 " " 1083 " " 1712 " " 2540 "Weapons (manuf.)" 2611 " " 4635 "Tobacco (wholes.)" 4645 " " 4648 " " 4642 " " 6492 "Credit granting" 6512 " " 9200 " " 9311 " " 9313 " " 4120 " " 4520 " " 5510 " " 5610 " " 6419 " " 8411 " "								
label values noga20084 nogaGraph
gen positionind = 3
replace positionind = 12  if noga20084 == 2540|noga20084 == 2611
replace positionind = 9  if noga20084 == 4645|noga20084 == 4120|noga20084 == 1083
replace positionind = 6  if noga20084 == 4642
twoway (scatter grosswage_rhrl i_j_s1, mlabel(noga20084) mlabv(positionind) mlabsize(small) mcolor(black) mlabcolor(black)) (lfit grosswage_rhrl i_j_s1, color(gs6) lpattern(dash)), graphregion(color(white)) legend(off) xtitle(Perceived industry immorality) ytitle(Average gross hourly wage (in CHF)) caption("")
graph export "$path_package/Main Figures/Figure_1a.pdf", replace
restore

* Panel (b)
preserve
keep if i_j_s2!=.
label define nogaGraph 2540 "Weapons (manuf.)" 4635 "Tobacco (wholes.)" 6492 "Credit granting" 1011 " " 1012 " " 8810	" " 8730	" " 8425	" " 8520	" " 8610	" " 1085	" " 4666	" " 5813	" " 6419	" " 4910	" " 1610	" " 8553	" " 6612	" " 1811	" " 119	" " 130	" " 8292	" " 2594	" " 4120	" " 2894	" " 8621	" " 6420	" " 4754	" " 4531	" " 4622	" " 4773	" " 6611	" " 1089	" " 9609	" " 2620	" " 4332	" " 4634	" " 5530	" " 2670	" " 7711	" " 4669	" " 4690	" " 150	" " 2751	" " 6511	" " 2319	" " 4646	" " 4932	" " 8891	" " 1072	" "
label values noga20084 nogaGraph
gen positionind = 3 
replace positionind = 6 if noga20084==1072|noga20084==2319|noga20084==4332|noga20084==4666|noga20084==6492
replace positionind = 9 if noga20084==2540|noga20084==4635|noga20084==2594|noga20084==4773|noga20084==4754|noga20084==4622|noga20084==119|noga20084==8610|noga20084==2620|noga20084==6419
replace positionind = 12 if noga20084==4669| noga20084==2670|noga20084==4690|noga20084==1085|noga20084==150|noga20084==2751|noga20084==2894
twoway (scatter grosswage_rhrl i_j_s2, mlabel(noga20084) mlabv(positionind) mlabsize(small) mcolor(black) mlabcolor(black)) (lfit grosswage_rhrl i_j_s2, color(gs6) lpattern(dash)), graphregion(color(white)) legend(off) xtitle(Perceived industry immorality) ytitle(Average gross hourly wage (in CHF)) caption("")
graph export "$path_package/Main Figures/Figure_1b.pdf", replace
restore

* Panel (c)
preserve
keep if i_j_s3!=.
label define nogaGraph 2540 "Weapons (manuf.)       ." 4635 "Tobacco (wholes.)" 6492 "Credit granting" 1011 " " 1012 " " 8810	" " 8730	" " 8425	" " 8520	" " 8610	" " 1085	" " 4666	" " 5813	" " 6419	" " 4910	" " 1610	" " 8553	" " 6612	" " 1811	" " 119	" " 130	" " 8292	" " 2594	" " 4120	" " 2894	" " 8621	" " 6420	" " 4754	" " 4531	" " 4622	" " 4773	" " 6611	" " 1089	" " 9609	" " 2620	" " 4332	" " 4634	" " 5530	" " 2670	" " 7711	" " 4669	" " 4690	" " 150	" " 2751	" " 6511	" " 2319	" " 4646	" " 4932	" " 8891	" " 1072	" "
label values noga20084 nogaGraph
gen positionind = 3 
replace positionind = 6 if noga20084==6492|noga20084==1072|noga20084==2319|noga20084==4332|noga20084==4666
replace positionind = 9 if noga20084==4635|noga20084==2594|noga20084==4773|noga20084==4754|noga20084==4622|noga20084==119|noga20084==8610|noga20084==2620|noga20084==6419
replace positionind = 12 if noga20084==2540|noga20084==4669| noga20084==2670|noga20084==4690|noga20084==1085|noga20084==150|noga20084==2751|noga20084==2894
twoway (scatter grosswage_rhrl i_j_s3, mlabel(noga20084) mlabv(positionind) mlabsize(small) mcolor(black) mlabcolor(black)) (lfit grosswage_rhrl i_j_s3, color(gs6) lpattern(dash)), graphregion(color(white)) legend(off) xtitle(Perceived industry immorality) ytitle(Average gross hourly wage (in CHF)) caption("")
graph export "$path_package/Main Figures/Figure_1c.pdf", replace
restore


/***************************
*
* Section 5 (Study 1)
*
*****************************/

cd "$path_package/Study 1"

**** Section 5.2.1
use Data_Individual.dta, clear
tabu low_theta

*** Section 5.2.2 (Sorting)
use Data_Individual.dta, clear
gen never_particpated = (not_participate==1)
reg never_particpated low_theta if !moral, cluster(sessiongr)
table moral low_theta, c(mean never_part )

use Data_Market_Microlevel.dta, clear
gen immoral = 1 - moral
gen participate = 1 - not_participate

table immoral low_theta, c(mean participate mean wagerequest)

** Table 1
* Specifications (1) to (4):
preserve
replace wagerequest=50 if wagerequest==.
replace wagerequest2=50 if wagerequest2==. 
gen neutral_low_theta = moral * low_theta
probit participate low_theta if immoral, cluster(sessiongr)
truncreg wagerequest low_theta moral neutral_low_theta, ul(50) cluster(sessiongr)
test low_theta + neutral_low_theta==0
reg hired1 low_theta moral neutral_low_theta, cluster(sessiongroup)
test low_theta + neutral_low_theta==0
gen hired_tot = hired1 + hired2
reg hired_tot low_theta moral neutral_low_theta, cluster(sessiongroup)
test low_theta + neutral_low_theta==0
restore

*** Section 5.2.3 (Wage premium)

* Figure 2a
use Data_Market_Microlevel.dta, clear
keep sessionsubject sessiongroup wagerequest wagerequest2 period moral
rename wagerequest wagerequest1
reshape long wagerequest, i(sessionsubject period sessiongroup) j(j)
drop j
replace wagerequest=50 if wagerequest==.
gsort +sessiongroup +period +wagerequest
by sessiongroup period: gen rank=_n
bysort rank moral: egen mean_wagerequest = mean(wagerequest)
line mean_wagerequest rank if moral==0, c(ascending) connect(stepstair) lpattern(longdash) lwidth(medthick) lcolor(gs6) || line mean_wagerequest rank if moral==1, c(ascending) connect(stepstair) lwidth(medthick) lcolor(black) ||  function y=2.5, range(1 6)  lcolor(gs8) lpattern(shortdash) lwidth(medthick) || function y=5.5, range(6 12) lcolor(gs8) lpattern(shortdash) lwidth(medthick) || function y=6, range(2.5 5.5) lcolor(gs8) horizontal lpattern(shortdash) lwidth(medthick) ||, legend(label(1 "Immoral work") label(2 "Neutral work")  label(3 "Induced costs") label(4 "")) ylabel(0(5)50) xlabel(1(1)12) ytitle("Wage (in CHF)") xtitle("Quantity") legend(on order(1 2 3)) plotregion(fcolor(white)) graphregion(fcolor(white))
graph export "$path_package/Main Figures/Figure_2a.pdf", replace

* Figure 2b
use Data_Market_Macrolevel.dta, replace
gen immoral = 1 - moral
bysort moral period: egen av_w = mean(equw)
line av_w period if moral==0, c(ascending) lpattern(longdash) lwidth(medthick) lcolor(gs6) || line av_w period if moral==1, c(ascending) lwidth(medthick) lcolor(black) || function y=2.9, range(1 15) lpattern(shortdash) lwidth(medthick) lcolor(gs8) ||, legend(label(1 "Immoral work") label(2 "Neutral work") label(3 "Equilibrium prediction")) ylabel(2.5(0.5)6) xlabel(1(1)15) ytitle("Average market wage (in CHF)") xtitle("Period") plotregion(fcolor(white)) graphregion(fcolor(white))
graph export "$path_package/Main Figures/Figure_2b.pdf", replace

reg equw immoral, cluster(sessiongr)


/***************************
*
* Section 6 (Study 2)
*
*****************************/

cd "$path_package/Study 2"

**** Section 6.2
use Data_Individual.dta, clear
tabu low_theta


*** Section 6.2.1 (Sorting)

use Data_Market_Microlevel.dta, clear
gen participate = 1 - not_participate

table treatment low_theta, c(mean participate mean wagerequest)

** Table 2
* Specifications (1) and (2):

preserve
replace wagerequest=50 if wagerequest==.
replace wagerequest2=50 if wagerequest2==. 

gen immoral_low_theta = immoral * low_theta
gen moral_low_theta = moral * low_theta
gen neutral_low_theta = neutral * low_theta

probit participate low_theta moral neutral moral_low_theta neutral_low_theta, cluster(sessiongr)
test low_theta + moral_low_theta==0
test low_theta + neutral_low_theta==0
test moral==neutral
test moral_low_theta== neutral_low_theta

truncreg wagerequest low_theta moral neutral moral_low_theta neutral_low_theta, ul(50) cluster(sessiongr)
test low_theta + moral_low_theta==0
test low_theta + neutral_low_theta==0
test moral==neutral
test moral_low_theta==neutral_low_theta

* specification (3)
reg hired1 low_theta moral neutral moral_low_theta neutral_low_theta, cluster(sessiongroup)
test low_theta + moral_low_theta == 0
test low_theta + neutral_low_theta == 0
test moral==neutral
test neutral_low_theta == moral_low_theta

* specification (4)
reg hired_tot low_theta moral neutral moral_low_theta neutral_low_theta, cluster(sessiongroup)
test low_theta + moral_low_theta == 0
test low_theta + neutral_low_theta == 0
test moral==neutral
test neutral_low_theta == moral_low_theta


*** Section 6.2.2 (Wage premium)

use Data_Market_Macrolevel.dta, clear

reg equw moral neutral, cluster(sessiongr)
test moral==neutral

table treatment if period>7, c(mean equw)

reg equw moral neutral if period>7, cluster(sessiongr)

reg equw immoral moral, cluster(sessiongr)


*** Section 6.2.3 (moral conduct at work)
use Data_Jobs.dta, clear

table low_theta if (moral | immoral), c(mean moral_action)
reg moral_action low_theta if (moral | immoral), cluster(sessiongroup)

reg moral_action immoral if (moral | immoral), cluster(sessiongroup)

gen lnwage = ln(equw)
reg moral_action immoral lnwage if (moral | immoral), cluster(sessiongroup)


/***************************
*
* Section 7 (Study 1)
*
*****************************/

cd "$path_package/Study 1"

*** Figure 3

use Data_WTW.dta, clear
drop if age==.
gen high_theta = 1-low_theta

mat estimates = J(20,3,.)

local j = 1

foreach industry in 1083 1200 1712 2540 2611 4120 4520 4635 4642 4645 4648 5510 5610 6419 6492 6512 8411 9200 9311 9313 {

reg WTW high_theta if NOGA084 ==`industry', robust
scalar beta = _b[high_theta]
matrix estimates[`j',1] = beta

sum i_j_s1 if NOGA084 ==`industry'
scalar i_j = r(mean)
matrix estimates[`j',2] = i_j

matrix estimates[`j',3] = `industry'

local j = `j' + 1

}

clear

svmat estimates
rename estimates1 beta
rename estimates2 i_j
rename estimates3 NOGA084

gen dependentvar=""
replace dependentvar = "Monetary intermediations" if NOGA084 == 6419
replace dependentvar = "Gambling and betting" if NOGA084==9200
replace dependentvar = "Non-life insur." if NOGA084==6512
replace dependentvar = "Tobacco (manuf.)" if NOGA084==1200
replace dependentvar = "Perfumes (wholes.)" if NOGA084==4645
replace dependentvar = "Paper (manuf.)" if NOGA084==1712
replace dependentvar = "Tobacco (wholes.)" if NOGA084==4635
replace dependentvar = "Electronic (manuf.)" if NOGA084==2611
replace dependentvar = "Weapons (manuf.)" if NOGA084==2540
replace dependentvar = "Maintenance vehicles" if NOGA084==4520
replace dependentvar = "Hotels and accomodation" if NOGA084==5510
replace dependentvar = "Construction" if NOGA084==4120
replace dependentvar = "Public administration" if NOGA084==8411
replace dependentvar = "Restaurant activities" if NOGA084==5610
replace dependentvar = "Sports facilities" if NOGA084==9311
replace dependentvar = "Credit granting" if NOGA084==6492
replace dependentvar = "Tea and coffee" if NOGA084==1083
replace dependentvar = "Clothing and footwear" if NOGA084==4642
replace dependentvar = "Watches and jewelry" if NOGA084==4648
replace dependentvar = "Fitness facilities" if NOGA084==9313

gen position_ind_highth = 3
replace position_ind_highth = 9 if dependentvar == "Non-life insur." |dependentvar == "Tea and coffee" | dependentvar == "Sports facilities"  | dependentvar == "Hotels and accomodation" | dependentvar == "Watches and jewelry" | dependentvar == "Public administration" | dependentvar == "Weapons (manuf.)" 
replace position_ind_highth = 6 if dependentvar == "Perfumes (wholes.)" | dependentvar == "Credit granting"

twoway (scatter beta i_j, msize(small) mlabel(dependentvar) mlabv(position_ind_highth) mlabsize(small) mcolor(black) mlabcolor(black)) (lfit beta i_j, color(gs6) lpattern(dash)), xlabels(-1(1)1) ylabels(-0.15(0.05)0.15) xtitle("Perceived immorality I(j)") ytitle("Differences in willingness to work") plotregion(fcolor(white)) graphregion(fcolor(white)) legend(off)
graph export "$path_package/Main Figures/Figure_3a.pdf", replace

use Data_WTW.dta, clear
drop if age==.
gen high_theta = 1-low_theta

mat estimates = J(26,3,.)

local j = 1

foreach company in abb adecco creditsuisse ernstyoung firmenich glencore holcim marlboro migros monsanto nestle novartis phillipemorris projuventute pronatura redcross roche swatch swisscom swisslife syngenta tamoil ubs unicef winterthurass wwf {

reg WTW high_theta if description_comp =="`company'", robust
scalar beta = _b[high_theta]
matrix estimates[`j',1] = beta

sum i_j_s1 if description_comp =="`company'"
scalar i_j = r(mean)
matrix estimates[`j',2] = i_j

matrix estimates[`j',3] = `j'

local j = `j' + 1

}
clear

svmat estimates
rename estimates1 beta
rename estimates2 i_j
rename estimates3 company

gen company_name = ""

local j = 1
foreach company in abb adecco creditsuisse ernstyoung firmenich glencore holcim marlboro migros monsanto nestle novartis phillipemorris projuventute pronatura redcross roche swatch swisscom swisslife syngenta tamoil ubs unicef winterthurass wwf {
replace company_name = "`company'" if company==`j'
local j = `j' + 1
}

gen dependentvar = ""
replace dependentvar = "Glencore" if company_name=="glencore"
replace dependentvar = "Novartis" if company_name=="novartis"
replace dependentvar = "Roche" if company_name=="roche"
replace dependentvar = "ABB" if company_name=="abb"
replace dependentvar = "UNICEF" if company_name=="unicef"
replace dependentvar = "Adecco" if company_name=="adecco"
replace dependentvar = "Migros" if company_name=="migros"
replace dependentvar = "Holcim" if company_name=="holcim"
replace dependentvar = "Pro Juventute" if company_name=="projuventute"
replace dependentvar = "Credit Suisse" if company_name=="creditsuisse"
replace dependentvar = "Swisscom" if company_name=="swisscom"
replace dependentvar = "Swatch" if company_name=="swatch"
replace dependentvar = "UBS" if company_name=="ubs"
replace dependentvar = "Red Cross" if company_name=="redcross"
replace dependentvar = "Malboro" if company_name=="marlboro"
replace dependentvar = "Monsanto" if company_name=="monsanto"
replace dependentvar = "Nestle" if company_name=="nestle"
replace dependentvar = "WWF" if company_name=="wwf"
replace dependentvar = "Tamoil" if company_name=="tamoil"
replace dependentvar = "Ernst and Young" if company_name=="ernstyoung"
replace dependentvar = "Pro Natura" if company_name=="pronatura"
replace dependentvar = "Winterthur Assurances" if company_name=="winterthurass"
replace dependentvar = "Syngenta" if company_name=="syngenta"
replace dependentvar = "Firmenich" if company_name=="firmenich"
replace dependentvar = "Philip Morris" if company_name=="phillipemorris"
replace dependentvar = "Swiss life" if company_name=="swisslife"

gen position_firm_highth = 3
replace position_firm_highth = 3
replace position_firm_highth = 9 if dependentvar == "UNICEF" |dependentvar == "Holcim" |dependentvar == "Migros" |dependentvar == "Ernst and Young" 
replace position_firm_highth = 6 if dependentvar == "Swatch"| dependentvar == "ABB"| dependentvar == "Credit Suisse" | dependentvar == "Red Cross"
replace position_firm_highth = 12 if dependentvar == "Syngenta" |dependentvar == "Adecco"

twoway (scatter beta i_j, msize(small) mlabel(dependentvar) mlabv(position_firm_highth) mlabsize(small) mcolor(black) mlabcolor(black)) (lfit beta i_j, color(gs6) lpattern(dash)), xlabels(-1(1)1) ylabels(-0.15(0.05)0.15) xtitle("Perceived immorality I(j)") ytitle("Differences in willingness to work") plotregion(fcolor(white)) graphregion(fcolor(white)) legend(off)
graph export "$path_package/Main Figures/Figure_3b.pdf", replace

